package com.ykt.converter;

import com.ykt.common.constant.ParamNames;
import com.ykt.common.utils.DateUtil;
import com.ykt.common.utils.ModelUtil;
import com.ykt.common.utils.UB;
import com.ykt.model.Goods;
import com.ykt.vo.GoodsVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author long.hua
 * @version 1.0.0
 * @since 2016-04-20 00:08
 */
public class GoodsConverter {


    public static GoodsVo convert(Goods model){
        if(model == null){
            return null;
        }

        GoodsVo vo = new GoodsVo();
        BaseConverter.convert(vo, model);
        vo.setMarketId(UB.i(model.get(Goods.market_id)));
        vo.setShopId(UB.i(model.get(Goods.shop_id)));
        vo.setMgCatId(UB.i(model.get(Goods.mg_cat_id)));
        vo.setSgCatId(UB.i(model.get(Goods.sg_cat_id)));
        vo.setGoodsId(UB.i(model.get(Goods.id)));
        vo.setGoodsName(model.getStr(Goods.name));
        vo.setIcon(model.getStr(Goods.icon));
        vo.setInitPrice(ModelUtil.d(model, Goods.init_price));
        vo.setShowInitPrice(UB.i(model.get(Goods.show_init_price)));
        vo.setSalePrice(ModelUtil.d(model, Goods.sale_price));
        vo.setGoodsPrice(ModelUtil.d(model, Goods.sale_price));
        vo.setStock(UB.i(model.get(Goods.stock)));
        vo.setUnitId(UB.i(model.get(Goods.unit_id)));
        vo.setUnit(model.getStr(ParamNames.unitName));
        vo.setGoodsUnit(model.getStr(ParamNames.unitName));
        vo.setUnitSummary(model.getStr(ParamNames.unitSummary));
        vo.setStatus(model.getStr(Goods.status));
        vo.setOriginal(model.getStr(Goods.original));
        vo.setSummary(model.getStr(Goods.summary));
        vo.setUpdatedTime(DateUtil.hm(model.getDate(Goods.updated_time)));

        return vo;
    }

    public static List<GoodsVo> convert(List<Goods> goodses){
        List<GoodsVo>  vos = new ArrayList<>();

        if(goodses == null || goodses.isEmpty()){
            return vos;
        }

        for (Goods goods : goodses) {
            vos.add(convert(goods));
        }

        return vos;
    }
}
